home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 02 / torture.asm < prev    next >
Assembly Source File  |  1991-02-10  |  3KB  |  71 lines

  1. ; TORTURE.ASM -- Copyright 1991 by L. Brett Glass
  2. ; This "disassembler torture test" is designed to make
  3. ; life difficult for disassemblers and debuggers.
  4.  
  5.         .MODEL LARGE
  6.  
  7. CODE    SEGMENT PARA PUBLIC
  8.         ASSUME CS:CODE,DS:NOTHING,ES:NOTHING,SS:NOTHING
  9.  
  10. ; Execution starts here. The program executes a bunch of NOPs, followed by 
  11. ; a string of ADD [BX+SI],AL instructions. The stack is then moved over the 
  12. ; area, and execution is transferred to the REAL program via a push-ret 
  13. ; sequence. The intent is to throw the disassembler off the scent.
  14.  
  15. INIT:
  16.         PUSHF                    ; Push flags for upcoming IRET
  17.         XOR BX,BX                ; Clear BX and SI
  18.         XOR SI,SI
  19.         PUSH CS                  ; Move CS to DS.
  20.         POP DS
  21.         MOV AX,OFFSET STACKSTART ; Get new SP
  22.         REPT 256                 ; 256 NOPs
  23.         NOP
  24.         ENDM
  25.         REPT 255                 ; 255 copies of ADD [BX+SI],AL
  26.         ADD [BX+SI],AL
  27.         ENDM
  28.         XOR  AX,SI               ; XORing with zero does nothing, of course!
  29.         ADD  AX,BX               ; Same with adding zero
  30.         PUSH AX                  ; Push new SP
  31.         PUSH CS                  ; Push new SS
  32.         CLI                      ; Turning off interrupts can cause some
  33.                                  ; debuggers problems
  34.         POP SS                   ; Set up new stack OVER this code!
  35.         MOV AX,SEG REALCODE      ; DEBUG automatically executes a second
  36.                                  ; instruction after SS is loaded, which
  37.                                  ; will hide this load. The user will just
  38.                                  ; see SP being popped.
  39.         POP SP
  40.         PUSH AX                  ; Get destination segment onto stack 
  41.                                  ; below flags.
  42.         PUSH BX                  ; By now, a disassembler may have "forgotten"
  43.                                  ; that this is zero. We're jumping to offset
  44.                                  ; zero in the segment REALCODE.
  45.         IRET                     ; Pop initial flags into flag reg, then jump
  46.                                  ; to start of "real" code. Interrupts are
  47.                                  ; turned back on here when the code is run.
  48.                                  ; But a debugger, which must turn interrupts
  49.                                  ; on between every pair of instructions, will
  50.                                  ; turn them on earlier and trash this opcode!
  51. STACKSTART:
  52.  
  53. CODE ENDS
  54.  
  55. REALCODE SEGMENT PARA PUBLIC
  56.      ASSUME CS:CODE,DS:NOTHING,ES:NOTHING,SS:NOTHING
  57.      MOV AX,SEG DATA
  58.      PUSH AX
  59.      POP DS
  60.      MOV DX,OFFSET Message  ; Prepare to print message
  61.      MOV AH,9               ; Print message through DOS
  62.      INT 21h             
  63.      MOV AX,4C00h           ; and EXIT
  64.      INT 21h
  65. REALCODE ENDS
  66.  
  67. DATA SEGMENT
  68. Message  db 'Disassembler test',0Dh,0Ah,'$'
  69. DATA ENDS
  70.  
  71.